package com.ruoyi.knowledge.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.domain.knowledge.Topic;
import com.ruoyi.knowledge.topic.service.ITopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 话题管理Controller
 * 
 * @author Jm
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/knowledge/topic")
public class TopicController extends BaseController
{
    @Autowired
    private ITopicService topicService;

    /**
     * 查询话题管理列表
     */
    @PreAuthorize("@ss.hasPermi('knowledge:topic:list')")
    @GetMapping("/list")
    public TableDataInfo list(Topic topic)
    {
        startPage();
        List<Topic> list = topicService.selectTopicList(topic);
        return getDataTable(list);
    }

    /**
     * 导出话题管理列表
     */
    @PreAuthorize("@ss.hasPermi('knowledge:topic:export')")
    @Log(title = "话题管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Topic topic)
    {
        List<Topic> list = topicService.selectTopicList(topic);
        ExcelUtil<Topic> util = new ExcelUtil<Topic>(Topic.class);
        util.exportExcel(response, list, "话题管理数据");
    }

    /**
     * 获取话题管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('knowledge:topic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(topicService.selectTopicById(id));
    }

    /**
     * 新增话题管理
     */
    @PreAuthorize("@ss.hasPermi('knowledge:topic:add')")
    @Log(title = "话题管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Topic topic)
    {
        return toAjax(topicService.insertTopic(topic));
    }

    /**
     * 修改话题管理
     */
    @PreAuthorize("@ss.hasPermi('knowledge:topic:edit')")
    @Log(title = "话题管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Topic topic)
    {
        return toAjax(topicService.updateTopic(topic));
    }

    /**
     * 删除话题管理
     */
    @PreAuthorize("@ss.hasPermi('knowledge:topic:remove')")
    @Log(title = "话题管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(topicService.deleteTopicByIds(ids));
    }
}